/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.entity;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * The <code>RealPhoneNumber</code> class represents phone number.
 * @author  Maxim Vasilevsky
 * @author  Roman Dyatkovsky
 * @since APUS v0.1
 */
public class RealPhoneNumber extends AbstractRealEntity implements PhoneNumber{
    
    /** The owner of number */
    private Subscriber owner;
    
    /** Phone number in international format. */
    private String number;
    
    /** List of out calls */
    private List<Call> outCalls = new ArrayList<>();
    
    /** List of in calls */
    private List<Call> inCalls = new ArrayList<>();

    /**
     * Default constructor.
     */
    public RealPhoneNumber() {
    }
    
    public RealPhoneNumber(int id){
        super(id);
    }
    
    /**
     * Initializes a newly created {@code PhoneNumber} object with an indication 
     * of number.
     * @param number Phone number.
     */
    public RealPhoneNumber(String number) {
        this.number = number;
    }
    
    /**
     * Initializes a newly created {@code PhoneNumber} object with an indication 
     * of number and owner.
     * @param owner Owner of the phone number.
     * @param number Phone number.
     */
    public RealPhoneNumber(Subscriber owner, String number) {
        this.owner = owner;
        this.number = number;
    }
    
    /**
     * Gets cost of calls on this phone number.
     * @return cost of call.
     */
    @Override
    public BigDecimal getCost() {
        return DEFAULT_COST;
    }
    
    /**
     * Gets list of calls from this phone number.
     * @return List of in calls.
     */
    @Override
    public List<Call> getInCalls() {
        return inCalls;
    }

    /**
     * Gets phone number.
     * @return Phone number.
     */
    @Override
    public String getNumber() {
        return number;
    }

    /**
     * Gets list of calls to this phone number.
     * @return List of out calls.
     */
    @Override
    public List<Call> getOutCalls() {
        return outCalls;
    }

    /**
     * Gets owner of the phone number.
     * @return Owner of the phone number.
     */
    @Override
    public Subscriber getOwner() {
        return owner;
    }

    /**
     * Sets owner of the phone number.
     * @param owner Owner of the phone number.
     */
    @Override
    public void setOwner(Subscriber owner) {
        this.owner = owner;
    }
    
    @Override
    public void setNumber(String number) {
        this.number = number;
    }

    /**
     * Adds incoming call.
     * @param inCall Incoming call.
     */
    @Override
    public void addInCall(Call inCall){
        this.inCalls.add(inCall);
    }
    
    /**
     * Adds outcoming call.
     * @param outCall Outcoming call.
     */
    @Override
    public void addOutCall(Call outCall){
        this.outCalls.add(outCall);
    }
    
    @Override
    public String toString(){
        return number;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final RealPhoneNumber other = (RealPhoneNumber) obj;
        if (!Objects.equals(this.number, other.number)) {
            return false;
        }
        return true;
    }
    
}
